<script type="text/javascript">
$(document).ready(function(){

    $("#addFeed").click(function(event){
        event.preventDefault();
        loadView("/feed/activeaddfeed", $("#boxCreateFeed"), function(){
            prepareInputsForHints();
        });
    });

    // Bind category refresh to the submit of a new category
    $("#category").bind('updateCategories', function() {
        loadFeedCategory($('#category'), '/category/loadcategories', function(){
            loadFeedByCategory($('#category'), '/feed/loadfeedsbycategory', function(data){
                $('#feed').html(data);
            });  
        });
    });

    // Bind feed refresh to the submit of a new feed
    $('#feed').bind('updateFeeds',function() {
    	loadFeedByCategory($('#category'), '/feed/loadfeedsbycategory', function(data){
            $('#feed').html(data);
        });
    });
    
    $("#category").change(function(){
    	loadFeedByCategory($('#category'), '/feed/loadfeedsbycategory', function(data){
    	    $('#feed').html(data);
        });    
    });

    // Force category select to load
    $("#category").trigger('updateCategories');
    
    var boxOptions = {
        dataType: "json",    
        success: function(data) { 
            if (data.error == false) { 
                jQuery.facebox("<?= $this->translate('okMsg') ?>");
            } else { 
                jQuery.facebox(parseJsonValidation(data.messages));
            }
        },
        error:   function (xhr, ajaxOptions, thrownError) {
            jQuery.facebox("<?= $this->translate('ajaxError') ?>");
        }
    };

    $('#indexbox').ajaxForm(boxOptions);
});
</script>

<form id="<?= $this->escape($this->formAddIndexPageBox->getAttrib("id"))?>"
      class="<?= $this->escape($this->formAddIndexPageBox->getAttrib("class"))?>" 
      action="<?= $this->escape($this->formAddIndexPageBox->getAction())?>" 
      method="<?= $this->escape($this->formAddIndexPageBox->getMethod())?>">
      <ul>
          <?= $this->formAddIndexPageBox->title ?>  
          <?= $this->formAddIndexPageBox->isPublished ?>
          <li class="element-group">
              <div class="element-group-selectblock">
	           <?= $this->formAddIndexPageBox->category ?>
	          </div> 
	          <div class="element-group-selectblockFeed">  
		          <?= $this->formAddIndexPageBox->feed ?>
		          <div class="element-group-selectblock">
		                <p id="addFeed" class="addbox">+</p>
		          </div>
		      </div>
          </li>
          <li class="element-group-addFeed">
              <div id="boxCreateFeed" class="boxCreateFeed">
                <!-- visualizzazione del box di creazione feed tramite ajax -->
              </div>
           </li>
          <?= $this->formAddIndexPageBox->submit ?>
      </ul>
</form>      